package com.ky.tms.controller;


import com.ky.tms.entity.TmsCar;
import com.ky.tms.entity.TmsCarInsure;
import com.ky.tms.entity.TmsCarOil;
import com.ky.tms.entity.TmsOil;
import com.ky.tms.exception.PredictableException;
import com.ky.tms.service.ITmsCarInsureService;
import com.ky.tms.service.ITmsCarOilService;
import com.ky.tms.service.ITmsCarService;
import com.ky.tms.service.ITmsOilService;
import com.ky.tms.util.CommonResult;
import com.ky.tms.util.JwtUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chengkaimao
 * @since 2020-05-13
 */
@RestController
@RequestMapping("/tms/tms-car")
public class TmsCarController {

    @Autowired
    private ITmsCarService tmsCarService;

    @Autowired
    private ITmsCarOilService tmsCarOilService;

    @ApiOperation("油卡数据分页")
    @GetMapping("page")
    public CommonResult page(TmsCar tmsCar, @RequestParam Long pageSize, @RequestParam Long current, HttpServletRequest request){
        return CommonResult.buildSuccess(tmsCarService.page(tmsCar, pageSize, current));
    }

    @ApiOperation("加油记录分页")
    @GetMapping("oil-page")
    public CommonResult oilPage(TmsCarOil tmsCarOil, @RequestParam Long pageSize, @RequestParam Long current){
        return CommonResult.buildSuccess(tmsCarOilService.oilPage(tmsCarOil,pageSize,current));
    }

    @ApiOperation("创建车辆")
    @PostMapping
    public CommonResult add(@RequestBody TmsCar tmsCar) throws PredictableException {
        tmsCarService.add(tmsCar);
        return CommonResult.buildSuccess(null);
    }

    @ApiOperation("修改车辆")
    @PutMapping
    public CommonResult update(@RequestBody TmsCar tmsCar) throws PredictableException {
        tmsCarService.update(tmsCar);
        return CommonResult.buildSuccess(null);
    }

    @ApiOperation("删除车辆")
    @DeleteMapping
    public CommonResult delete(@RequestBody List<Long> ids){
        tmsCarService.delete(ids);
        return CommonResult.buildSuccess(null);
    }

    @ApiOperation("加油")
    @PostMapping("oil")
    public CommonResult oil(@RequestBody TmsCarOil tmsCarOil) throws PredictableException {
        tmsCarService.oil(tmsCarOil);
        return CommonResult.buildSuccess(null);
    }

    @ApiOperation("保险购买")
    @PostMapping("insure")
    public CommonResult insure(@RequestBody TmsCarInsure tmsCarInsure) throws PredictableException {
        tmsCarService.insure(tmsCarInsure);
        return CommonResult.buildSuccess(null);
    }


}
